Skip to content

fixing use-strict issue with connectors after merge #2632 - #2977

Merged
loay merged 1 commit into
strongloop:masterfrom
ebarault:fix-issue-post-merge-#2632
Nov 30, 2016
Merged

loay merged 1 commit into
strongloop:masterfrom
ebarault:fix-issue-post-merge-#2632

Conversation

@ebarault

@ebarault ebarault commented Nov 23, 2016 •

Copy link
Copy Markdown
Contributor

Description

adding 'use strict' in lib/application.js on recent code style review broke the support for db connectors here : https://github.com/strongloop/loopback/blob/master/lib/application.js#L427

This PR solves this issue by looking at config.connector type before trying to assign config.connector.name property

All tests pass. No need for new tests

Related issues

#2632 (comment)
#2978

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

3 similar comments
@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

@ebarault
ebarault force-pushed the fix-issue-post-merge-#2632 branch from 2639ff0 to b1eb96f Compare November 23, 2016 14:27
@loay loay self-assigned this Nov 23, 2016
Comment thread lib/application.js Outdated
}
}
if (!config.connector.name)
if (typeof config.connector !== 'string' && !config.connector.name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking of using:
if (!config.connector)
^ Did you try that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @loay ,
if (!config.connector) won't work alone, as config.connector is indeed initialized to, say, mongodb, or mysql, etc. if datasources.json is correctly set up.

But still I can tinker by adding turning the test this way:
if (config.connector && typeof config.connector.name === 'object')

of course comparing object type is not 100% safe (arrays, dates, null which is already checked here), but i think it's robust enough given the surrounding code

loay
loay previously requested changes Nov 23, 2016

@loay loay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing use-strict issue with connectors after merge: First line should be 50 characters or less (saw 57)
Can you please reduce this to 50 char?
Then rebase please. Thanks.

@ebarault ebarault closed this Nov 23, 2016
@ebarault
ebarault force-pushed the fix-issue-post-merge-#2632 branch from b1eb96f to 2c1ebdc Compare November 23, 2016 22:34
@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

3 similar comments
@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Nov 23, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

@ebarault

ebarault commented Nov 23, 2016 •

Copy link
Copy Markdown
Contributor Author

@loay
reposting my previous msg here :

testing if (!config.connector) won't work alone, as config.connector is indeed initialized to, e.g. mongodb, or mysql, etc. if datasources.json is correctly set up.

But still I can tinker by adding turning the test this way:
if (config.connector && typeof config.connector.name === 'object' && ..)

of course comparing object type is not 100% safe (arrays, dates, null which is already checked here), but i think it's robust enough given the surrounding code

i also rebased

@loay

loay commented Nov 24, 2016

Copy link
Copy Markdown
Contributor

Hey @ebarault, thanks for rebasing.
yes you are right, I tried to run the tests on the module itself and it didn't work with (!config.connector), even if it was working in the example app.
You can leave it as it used to be.
@bajtos @superkhau .. Any thoughts?

if (typeof config.connector !== 'string' && !config.connector.name)
vs
if (config.connector && typeof config.connector === 'object' && !config.connector.name)
to fix this bug?

@loay loay added the team-apex label Nov 25, 2016
@loay

loay commented Nov 29, 2016

Copy link
Copy Markdown
Contributor

@slnode test please

@ebarault
ebarault force-pushed the fix-issue-post-merge-#2632 branch from b8119a6 to 33a5ad6 Compare November 29, 2016 22:22
@ebarault

Copy link
Copy Markdown
Contributor Author

@loay : just rebased. please go on

@loay

loay commented Nov 30, 2016

Copy link
Copy Markdown
Contributor

@ebarault Thanks.

@loay

loay commented Nov 30, 2016

Copy link
Copy Markdown
Contributor

@slnode test please

@bajtos
bajtos force-pushed the fix-issue-post-merge-#2632 branch from 33a5ad6 to d239476 Compare November 30, 2016 15:58
@bajtos

bajtos commented Nov 30, 2016

Copy link
Copy Markdown
Member

Thank you for the pull request, @ebarault.

I have reworded the commit message to make it more descriptive and git push -f to your feature branch.

@bajtos bajtos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bajtos
bajtos dismissed loay’s stale review November 30, 2016 16:00

I have made the final changes myself.

@loay

loay commented Nov 30, 2016

Copy link
Copy Markdown
Contributor

@slnode test please

@loay
loay force-pushed the fix-issue-post-merge-#2632 branch from 51e8024 to 5611f60 Compare November 30, 2016 18:52
In strict mode, creating properties on strings is not allowed.
As a result, creating a new datasource fails with the following
error:

    TypeError: Cannot create data source "db":
    Cannot create property 'name' on string 'mongodb'

In this commit, we fix the code to assign the connector name only
if the connector is an object (not a string).

Add "returnOnlyRoleNames" option to Role.getRoles

Currently the return type of Role.getRoles() method is inconsistent:
role names are returned for smart roles and role ids are returned for
static roles (configured through user-role mapping).

This commit adds a new option to Role.getRoles() allowing the caller
to request role names to be returned for all types of roles.
@loay
loay force-pushed the fix-issue-post-merge-#2632 branch from 8b23a34 to 94c786f Compare November 30, 2016 19:09
@loay

loay commented Nov 30, 2016

Copy link
Copy Markdown
Contributor

@slnode test please

@loay
loay merged commit a34f321 into strongloop:master Nov 30, 2016
@loay

loay commented Nov 30, 2016

Copy link
Copy Markdown
Contributor

Thanks @ebarault for your contribution. Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants